package com.jzo2o.market.controller.inner;

import com.jzo2o.api.market.CouponApi;
import com.jzo2o.api.market.dto.request.CouponUseBackReqDTO;
import com.jzo2o.api.market.dto.request.CouponUseReqDTO;
import com.jzo2o.api.market.dto.response.AvailableCouponsResDTO;
import com.jzo2o.api.market.dto.response.CouponUseResDTO;
import com.jzo2o.market.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * 内部接口 - 优惠卷相关接口
 *
 * @author Zhy
 * @version 1.0
 * @date 2025-04-11 9:27
 */
@RestController
@Api(tags = "内部接口 - 优惠卷相关接口")
@RequestMapping("/inner/coupon")
public class CouponController implements CouponApi {

	@Resource
	private ICouponService couponService;

	/**
	 * 获取可用优惠卷列表
	 *
	 * @return:
	 * @param:
	 */
	@Override
	@GetMapping("/getAvailable")
	@ApiOperation("获取可用优惠券列表")
	@ApiImplicitParam(name = "totalAmount", value = "总金额，单位分", required = true, dataTypeClass = BigDecimal.class)
	public List<AvailableCouponsResDTO> getAvailable(BigDecimal totalAmount) {
		return couponService.getAvailableCoupons(totalAmount);
	}

	/**
	 * 优惠券使用，并返回优惠金额
	 *
	 * @param couponUseReqDTO 优惠券使用请求参数
	 */
	@Override
	@PostMapping("/use")
	@ApiOperation("优惠券使用，并返回优惠金额")
	@ApiImplicitParam(name = "totalAmount", value = "总金额，单位分", required = true, dataTypeClass = BigDecimal.class)
	public CouponUseResDTO use(@RequestBody CouponUseReqDTO couponUseReqDTO) {
		return couponService.useCoupon(couponUseReqDTO);
	}

	@Override
	@PostMapping("/useBack")
	@ApiOperation("优惠券退回接口")
	public void useBack(@RequestBody CouponUseBackReqDTO couponUseBackReqDTO) {
		// TODO 优惠券退回接口实现
	}

}
